package com.hsp.static_;

public class ChildGame {
    public static void main(String[] args) {
        Child child1 = new Child("白骨精");
        child1.join();
//        child1.count++;
        Child child2 = new Child("狐狸精");
        child1.join();
//        child1.count++;
        Child child3 = new Child("老鼠精");
        child3.join();
//        child3.count++;

//        类变量可以通过类名来访问
        System.out.println("共有"+Child.count+"小孩加入游戏...");
        System.out.println("child1.count="+child1.count);
        System.out.println("child2.count="+child2.count);
        System.out.println("child3.count="+child3.count);
    }
}

class Child{
    private String name;
    //定义一个静态变量count,是一个类变量（静态变量）static静态
    //该变量会被child共享
    public static int count=0;

    public Child(String name) {
        this.name = name;
    }
    public void join(){
        this.count++;
        System.out.println(name+"玩游戏");
    }
}
